import requests
from bs4 import BeautifulSoup

url = 'https://inst.eecs.berkeley.edu/~cs61a/fa20/assets/slides/'

resp = requests.get(url)

bs = BeautifulSoup(resp.content.decode('utf-8'), features='html.parser')
resp.close()
tags = bs.find_all('a')

# print(tags)

for tag in tags:
    # print(tag.attrs['href'])
    href = tag.attrs['href']
    if href.endswith('1pp.pdf') or href.endswith('.py'):
        target_url = url + href
        print(target_url)
        res = requests.get(target_url)
        with open(f'/home/huo/code/python-project/ppt/{href}', mode='wb') as f:
            f.write(res.content)
